#ifndef DOCKMANAGER_H
#define DOCKMANAGER_H

#include "qdock.h"


class DockManager : public QObject{
    Q_OBJECT

    enum State {
        Default = 0,
        Dragging = 1,
        Pulling = 2,
        Shifted = 4
    };

public:
    DockManager();

public slots:
    void mouseDown(QDockItem *widget, const QPoint &point, const QPoint &m_offset);
    void mouseMove(QDockItem* widget, const QPoint &point);
    void mouseUp(QDockItem* widget, const QPoint & point);
    void keyPress(QDockItem* dw, QKeyEvent* event);
public:
    UDockWidgetPreviewer* previewer() const{return m_previewer;}
    void setPreviewer(UDockWidgetPreviewer* previewer);

    QPolicyManager* policyManager() const{return m_policymanager;}
    void setPolicyManager(QPolicyManager* policymanager);

    QLayoutManager* layoutManager() const{return m_layoutmanager;}
    void setLayoutManager(QLayoutManager* ilym){m_layoutmanager = ilym;}

protected:
    void stopDrag();
    void startDrag();
    std::unordered_set<Window> ignores(QWidget *widget) const;
    void startPull();
    void stopPull();
    void pulling(QDockItem *widget, const QPoint &point);
    void dragging(QDockItem *widget, const QPoint &point);
    void updateLastTarget(QDockItem *widget, const QPoint& point);

protected slots:
    void keyPressPulling(QKeyEvent* event);
    void keyPressDragging(QDockItem *dw, QKeyEvent* event);

protected:
    QPoint m_last_mouse_pos;
    UDockWidgetPreviewer* m_previewer;
    QLayoutManager* m_layoutmanager;
    QPolicyManager* m_policymanager;
    std::vector<Window> m_windows;
    std::vector<QDockItem*> m_dockitems;
    State m_state;
    QDockItem* m_dragging;
    QDockItem* m_mouse_grab;
    QDockItem* m_last_target;
    QPoint m_offset, m_dragstart;
    int m_dragtolerance;

};

#endif // DOCKMANAGER_H
